<?php
$schulungen = sqlServicesFunctions::getSchulungen();
$zeiten = sqlServicesFunctions::getZeiten();
$allTitel = sqlServicesFunctions::getTitel();
?>
<html lang="de">
<head>
<meta charset="utf-8">
<link rel="stylesheet"
	href="jquery-ui-1.10.4.custom/development-bundle/themes/custom-theme/jquery-ui.css">
<link rel="stylesheet" href="style.css">
<script>
  $(function() {
    var spinner = $( "#spinner" ).spinner();

  });
  
  $(function() {
	    $( "input[type=button], a, button" )
	      .button()
	      .click(function( event ) {
	        event.preventDefault();
	      });
  });
  function addRow(tableID) {

      var table = document.getElementById(tableID);

      var rowCount = table.rows.length;
      var row = table.insertRow(rowCount);

      var cellAnrede = row.insertCell(0);
      cellAnrede.innerHTML= document.getElementById("anredeSelect").value;

      var cellTitel = row.insertCell(1);
      cellTitel.innerHTML= document.getElementById("titelSelect").value;

      var cellVorname = row.insertCell(2);
      cellVorname.innerHTML= document.getElementById("vornameInput").value;

      var cellName = row.insertCell(3);
      cellName.innerHTML= document.getElementById("nameInput").value;
      
      var cellStrasse = row.insertCell(4);
      cellStrasse.innerHTML= document.getElementById("strasseInput").value;
    
      var cellHausNr = row.insertCell(5);
      cellHausNr.innerHTML= document.getElementById("hausnrInput").value;

      var cellPLZ = row.insertCell(6);
      cellPLZ.innerHTML= document.getElementById("plzInput").value;

      var cellOrt = row.insertCell(7);
      cellOrt.innerHTML= document.getElementById("ortInput").value;

      var cellTelefon = row.insertCell(8);
      cellTelefon.innerHTML= document.getElementById("telefonInput").value;    

      var cellTelefon = row.insertCell(9);
      cellTelefon.innerHTML= document.getElementById("emailInput").value;   
      
      var cellSchulung = row.insertCell(10);
      cellSchulung.innerHTML= document.getElementById("schulungSelect").value;
      
      var cellZeit = row.insertCell(11);
      cellZeit.innerHTML= document.getElementById("zeitSelect").value;

      var cellNotiz = row.insertCell(12);
      cellNotiz.innerHTML= document.getElementById("notizText").value;
      
      var cellDel = row.insertCell(13);
      var delBtn = "<INPUT type=\"image\" SRC=\"data/images/1396014435_Black_Trash.png\" onClick=\"deleteRow(this)\">";
      
	  cellDel.innerHTML = delBtn;
  }

  function deleteRow(btn) {
	  if(confirm(unescape("M%F6chten Sie diesen Eintrag l%F6schen%3F"))){
	  var row = btn.parentNode.parentNode;
	  row.parentNode.removeChild(row);
	};
  }
 </script>
</head>
<body>
<script type="text/javascript">

	function submit(idPerson, btn){
		
	$.getScript("classes/AJAXHelper.js", function() {
		var table = document.getElementById("anmeldeTable");
		var rows = table.rows;
		var i = 1;
		while (i < rows.length) {
			var cells = rows[i].cells;
	
			doAJAX("anmeldungCheck", idPerson + ","
				+ cells[0].innerHTML + ","
				+ cells[1].innerHTML + ","
				+ cells[2].innerHTML + ","
				+ cells[3].innerHTML + ","
				+ cells[4].innerHTML + ","
				+ cells[5].innerHTML + ","
				+ cells[6].innerHTML + ","
				+ cells[7].innerHTML + ","
				+ cells[8].innerHTML + ","
				+ cells[9].innerHTML + ","
				+ cells[10].innerHTML + ","
				+ cells[11].innerHTML + ","
				+ cells[12].innerHTML
				, function() {
					if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
						alert(xmlhttp.responseText);
					}
				});
				i++;
			}
	});

	}
</script>
<span id="hinweismeldungEinstellen"></span>
<table id="anmeldungEinstellenTabelle" style="width: 100%">
	<tr>
		<td><label style="width: 100%">Anrede</label></td>
		<td><select id="anredeSelect" style="width: 100%">
			<option value="Herr">Herr</option>
			<option value="Frau">Frau</option>
		</select></td>
		<td>Titel</td>
		<td><select id="titelSelect" style="width: 100%">
		<?php
		while ($titel = $allTitel->next()) {
			echo '<option value="' . $titel['TBezeichnung'] . '">' . $titel['TBezeichnung'] . '</option>';
		}
		?>
		</select></td>
	</tr>
	<tr>
		<td><label style="width: 100%">Vorname</label></td>
		<td><input id="vornameInput" name="vornameInput" type="text"
			style="width: 100%" onclick="this.select();"></input></td>
		<td><label style="width: 100%">Name</label></td>
		<td><input id="nameInput" style="width: 100%" onclick="this.select();"></input></td>
	</tr>
	<tr>
		<td><label style="width: 100%">Telefon</label></td>
		<td><input id="telefonInput" style="width: 100%"
			onclick="this.select();"></input></td>
		<td nowrap><label style="width: 100%">E-Mail</label></td>
		<td><input id="emailInput" style="width: 100%"
			onclick="this.select();"></input></td>
		<!-- td><label style="width: 100%">Fax</label></td>
		<td><input id="faxInput" style="width: 100%" onclick="this.select();"></input></td -->
	</tr>
	<tr>
		<td><label style="width: 100%">Stra&szlig;e</label></td>
		<td><input id="strasseInput" style="width: 100%"
			onclick="this.select();"></input></td>
		<td><label style="width: 100%">HausNr</label></td>
		<td><input id="hausnrInput" style="width: 100%" align="right"
			id="spinner" name="value"></td>
	</tr>
	<tr>
		<td><label style="width: 100%">PLZ</label></td>
		<td><input id="plzInput" style="width: 100%" onclick="this.select();"></input></td>
		<td><label style="width: 100%">Ort</label></td>
		<td><input id="ortInput" style="width: 100%" onclick="this.select();"></input></td>
	</tr>
	<tr>
		<td valign="top"><label style="width: 100%">Schulung</label></td>
		<td valign="top"><select id="schulungSelect" style="width: 100%">
		<?php
		while ($schulung = $schulungen->next()) {
			echo '<option value="' . $schulung['Beschreibung'] . '">' . $schulung['Beschreibung'] . '</option>';
		}
		?>
		</select></td>
		<td valign="top"><label style="width: 100%">Zeit</label></td>
		<td valign="top"><select id="zeitSelect" style="width: 100%">
		<?php
		while ($zeit = $zeiten->next()) {
			echo '<option value="' . $zeit['Bezeichnung'] . '">' . $zeit['Bezeichnung'] . '</option>';
		}
		?>
		</select></td>
		<td valign="top"><label style="width: 100%">Notiz</label></td>
		<td><textarea id="notizText" style="width: 100%" rows="5" cols="15"
			onclick="this.select();"></textarea></td>
		<td></td>
		<td>
		<button style="width: 100%">reset</button>
		<br>
		<input type="button" style="width: 100%"
			onclick="addRow('anmeldeTable')" value="hinzuf&uuml;gen"></td>
	</tr>
</table>


<table class="table" id="anmeldeTable" style="width: 100%">
	<tr>
		<td>Anrede</td>
		<td>Titel</td>
		<td>Vorname</td>
		<td>Name</td>
		<td>Stra&szlig;e</td>
		<td>HausNr</td>
		<td>PLZ</td>
		<td>Ort</td>
		<td>TelNr</td>
		<td>E-Mail</td>
		<td>Schulung</td>
		<td>Zeit</td>
		<td>Notiz</td>
		<td></td>
	</tr>
</table>
<input type="button" style="width: 100%"
	onclick="submit(<?php echo Session::getIDPerson()?>, this)"
	value="Anmeldung einstellen">

</body>
</html>
